package com.example.ordersys.controller;

import com.example.ordersys.mapper.DishMapper;
import com.example.ordersys.model.Dish;
import com.example.ordersys.model.OrderDetail;
import com.example.ordersys.tools.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Resource
    private DishMapper dishMapper;

    /**
     * 查询所有菜品信息
     */
    @RequestMapping("/list")
    public ResponseBody<List<Dish>> getList() {
        int status=-1;
        String message="获取菜单列表失败";
        List<Dish> data=null;
        data=dishMapper.getList();
        if (data!=null){
            status=0;
            message="";
        }
        return new ResponseBody<>(status,message,data);

    }

    /**
     * 添加菜品
     */
    @RequestMapping("/add")
    public ResponseBody<Integer> add(Dish dish) {
        int status=-1;
        String message="新增菜品失败";
        Integer data=0;

        if ((data=dishMapper.add(dish))>0){
            status=0;
            message="";
        }
        return new ResponseBody<Integer>(status,message,data);

    }

    /**
     * 修改菜品
     */
    @RequestMapping("/update")
    public int update(Dish dish) {
        return dishMapper.update(dish);
    }

    /**
     * 删除菜品
     */
    @RequestMapping("/del")
    public ResponseBody<Integer> del(@RequestParam int id) {
        int status=-1;
        String message="删除菜品失败";
        Integer data = 0;
        if ((data=dishMapper.del(id))>0){
            status=0;
            message="删除菜品成功";
        }
        return new ResponseBody<Integer>(status,message,data);
    }

}